/*------------------------------------------------------------------------------
 File:          boot_config.h
 Function:      Bootloader configuration
 Supported chip(s):
    - SAM3X8
    - SAM3X4
    - SAM3X2
 Supported toolchain(s):
    - IAR Embedded Workbench
 Date created:  28 Aug 2013
 Created by:    JPM team
 Notes:

 The config.h file defines the configuration of the bootloader, namely;
  - communication protocol used
  - media driver used
  - debug driver used (if any)
  - memory type
  - trigger condition
  - timing measurement peripheral (if any)
  - optional features (such as firmware encryption)

 To modify this file, simply comment/uncomment the desired lines. For example,
 if you want to select the DBGU/UART as the debug driver, then uncomment all
 lines under the Debug category except #define USE_DBGU (#define USE_UART).
 In some cases, there are parameters to adjust, e.g. the baudrate of the DBGU
 and USART line. Note that you do not need to uncomment parameters when the
 option is not selected, but you may do so.
*/

#ifndef BOOT_CONFIG_H
#define BOOT_CONFIG_H

#include "compiler.h"
//------------------------------------------------------------------------------
// Modes
//------------------------------------------------------------------------------

/**
 * Communication protocol (must be used)
 *  -> Xon/Xoff (USE_XON_XOFF)
 */
#define USE_XON_XOFF

/**
 * Media layer (must be used to load firmware)
 *  -> Usart #2 (USE_US2)
 */
#define USE_US2

//------------------------------------------------------------------------------
// Options
//------------------------------------------------------------------------------

/**
 * Name:    USE_BOOT_REGION_LOCKING
 * Effect:  Locks the boot region, denying write access on it.
 *          The boot segment must occupate a whole region, or it will
 *          not be possible to correctly program the application.
 *           => BOOTLOADEREND multiple of 0x4000
 */
#define USE_BOOT_REGION_LOCKING

/**
 * Name:    USE_MEMORY_PARTIONING
 * Effect:  When active, the application space in flash is divided into two
 *          regions. One act as a buffer to receive a firmware upgrade, while
 *          the other contains the code which will be executed. This makes it
 *          possible to have, at all time, at least one working firmware in the
 *          device (even after an upgrade failure).
 * Parameters:
 *          Uses dual bank partitioning (PARTITION_DUAL_BANK)
 *            -> The partition is based on dual bank flash.
 *            -> Note that REGION_SIZE in this case should be equal to
 *               (bank size - bootloader size - page size)
 *            -> One page is reserved to store information about regions
 *               -> Signatures, length of firmware, etc.
 *          Size of one region (REGION_SIZE)
 *            -> Note that max REGION_SIZE for single bank can be equal to
 *               (flash size - bootloader size - page size) / 2
 *            -> One page is reserved to store information about regions
 *               -> Signatures, length of firmware, etc.
 *            -> Ex with SAM7XC256, BOOTSIZE = 0x8000
 *               -> (0x40000 - 0x8000 - 0x100) / 2 = 0x1BF00
 *            -> Regions must be aligned on page and multiple of MEMORY_PAGE_SIZE
 */
#define USE_MEMORY_PARTITIONING

/** Bootloader size (default to 32K, 0x8000) */
#ifndef BOOTLOADER_SIZE
    #define BOOTLOADER_SIZE     (80*1024)
#endif
/**Region size*/
#ifndef REGION_SIZE
    #define REGION_SIZE     (80*1024)/*((IFLASH_SIZE - BOOTLOADER_SIZE - 3*MEMORY_PAGE_SIZE)/2)*/
#endif
/** Application A start address */
#ifndef APP_A_START_ADDRESS
    #define APP_A_START_ADDRESS ((void *) ((unsigned int) BOOTLOADER_SIZE + (unsigned int) IFLASH0_ADDR))
    #define APP_A_END_ADDRESS   ((void *) ((unsigned int) APP_A_START_ADDRESS + (unsigned int) REGION_SIZE -1))
#endif
/** Application B start address */
#ifndef APP_B_START_ADDRESS
    #define APP_B_START_ADDRESS ((void *) ((unsigned int) APP_A_START_ADDRESS + (unsigned int) REGION_SIZE))
    #define APP_B_END_ADDRESS   ((void *) ((unsigned int) APP_B_START_ADDRESS + (unsigned int) REGION_SIZE -1)) 
#endif
/** Boot info A address */
#ifndef BOOT_INFO_A_START_ADDRESS
    #define BOOT_INFO_A_START_ADDRESS ((void *) ((unsigned int) APP_B_START_ADDRESS + (unsigned int) REGION_SIZE))
#endif
/** Boot info B address */
#ifndef BOOT_INFO_B_START_ADDRESS
    #define BOOT_INFO_B_START_ADDRESS ((void *) ((unsigned int) BOOT_INFO_A_START_ADDRESS + (unsigned int) MEMORY_PAGE_SIZE))
#endif
/** Valid boot info address */
#ifndef BOOT_INFO_VALID_START_ADDRESS
    #define BOOT_INFO_VALID_START_ADDRESS ((void *) ((unsigned int) BOOT_INFO_B_START_ADDRESS + (unsigned int) MEMORY_PAGE_SIZE))
#endif

#endif // BOOTLOADER_CONFIG_H
